package com.erytech.linktalk.web.client.datasource;

import java.util.HashMap;

import com.erytech.linktalk.web.client.framework.DataSource;
import com.google.gwt.user.client.ui.Image;

public class SmileyDataSource extends DataSource {

	static final int ROW_COUNT = 8;
	static final int COL_COUNT = 12;
	
	HashMap smileyMap = new HashMap(100);
	
	int selected = 0;
	
	public SmileyDataSource() {
		int count = ROW_COUNT * COL_COUNT;
		for(int i = 0; i < count; i++) {
			smileyMap.put("" + i, new Image(getSmileySrc(i)));
		}
	}
	
	public int getRowCount() {
		return ROW_COUNT;
	}

	public int getColCount() {
		return COL_COUNT;
	}
	
	public String getSelected() {
		return String.valueOf(selected);
	}
	
	public void setSelected(int row, int col) {
		selected = getSmileyIndex(row, col);
		fireDataUpdateEvent(new SmileyChangeEvent(this, selected));
	}

	public Image getSmiley(int row, int col) {
		return (Image)smileyMap.get("" + getSmileyIndex(row, col));
	}
	
	public Image getSmiley(String index) {
		return (Image)smileyMap.get(index);
	}
	
	public String getSmileySrc(int index) {
		return "icons/qq_smiley_" + index + ".gif";
	}

	public int getSmileyIndex(int row, int col) {
		return (row * 10 + col);
	}

	public Image getSelectedSmiley() {
		return (Image)smileyMap.get(getSelected());
	}

}